package jjn.carl.binary_tree;

import commons.TreeNode;

/**
 * @author Jiang Jining
 * @since 2023-07-13 0:17
 */
public class LeetCode101 {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return isSymmetricPairs(root.left, root.right);
    }
    
    private boolean isSymmetricPairs(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null) {
            return false;
        }
        if (left.val != right.val) {
            return false;
        }
        return isSymmetricPairs(left.left, right.right) && isSymmetricPairs(left.right, right.left);
    }
}
